import {defineStore} from "pinia";

export const useIframeStore = defineStore('iframe', {
	state: () => ({
		iframeList: []
	}),
	actions: {
		setIframeList(route:any){
			this.iframeList = []
			// @ts-ignore
			this.iframeList.push(route)
		},
		pushIframeList(route:any){
			// @ts-ignore
			let target = this.iframeList.find((item) => item.path === route.path)
			if(!target){
				// @ts-ignore
				this.iframeList.push(route)
			}
		},
		removeIframeList(route:any){
			this.iframeList.forEach((item, index) => {
				// @ts-ignore
				if (item.path === route.path){
					this.iframeList.splice(index, 1)
				}
			})
		},
		refreshIframe(route:any){
			this.iframeList.forEach((item) => {
				// @ts-ignore
				if (item.path == route.path){
					var url = route.meta.url;
					// @ts-ignore
					item.meta.url = '';
					setTimeout(function() {
						// @ts-ignore
						item.meta.url = url
					}, 200);
				}
			})
		},
		clearIframeList(){
			this.iframeList = []
		}
	}
})
